//
//  CardNewsItemView.m
//  BaoVn
//
//  Created by Le Anh Tai on 11/9/14.
//  Copyright (c) 2014 Le Anh Tai. All rights reserved.
//

#import "CardNewsItemView.h"

@implementation CardNewsItemView

- (instancetype)init
{
    if (self = [super init])
    {        
        _gradientLayer = [CAGradientLayer layer];
        _gradientLayer.colors = @[(id)[[UIColor colorWithWhite:1.0f alpha:0.0f] CGColor],
                                  (id)[[UIColor colorWithWhite:0.3f alpha:0.7f] CGColor],
                                  (id)[[UIColor colorWithWhite:0.0f alpha:1.0f] CGColor]];
        _gradientLayer.locations = @[@0.00f,@0.30f, @1.00f];
        [self.layer insertSublayer:_gradientLayer below:self.titleLabel.layer];
        
        self.titleLabel.textColor = [UIColor whiteColor];
        self.descriptionLabel.textColor = [UIColor lightTextColor];
        self.createdDateLabel.textColor = [UIColor lightTextColor];
        self.descriptionLabel.numberOfLines = 2;
        
        self.marginBottom = 8;
    }
    
    return self;
}

- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    
    if (CGSizeEqualToSize(frame.size, CGSizeZero))
    {
        return;
    }
    
//    NSInteger maxHeiContent = 80;
//    NSInteger maxHeiTitle;
//    
//    [self.createdDateLabel sizeToFit];
//    
//    if (_hideImage)
//    {
//        _gradientLayer.frame = RECT(0, 0, self.width, self.height);
//        self.createdDateLabel.origin = POINT(self.marginLeft, self.height - self.createdDateLabel.height - self.marginBottom - (self.height - maxHeiContent)/2);
//    }
//    else
//    {
//        _gradientLayer.frame = RECT(0, self.height - maxHeiContent*2, self.width, maxHeiContent*2);
//        self.createdDateLabel.origin = POINT(self.marginLeft, self.height - self.createdDateLabel.height - self.marginBottom);
//    }
//    
//    self.imageView.frame = self.bounds;
//    
//    self.titleLabel.frame = RECT(self.marginLeft, self.createdDateLabel.top - maxHeiContent, self.width - self.marginLeft - self.marginRight, self.createdDateLabel.top);
//    [self.titleLabel sizeToFit];
//    maxHeiTitle = maxHeiContent - self.createdDateLabel.height - self.marginBottom;
//    if (self.titleLabel.height > maxHeiTitle)
//    {
//        self.titleLabel.height = maxHeiTitle;
//    }
//    
//    NSInteger minHeiDescription = 15;
//    if (self.createdDateLabel.top - self.titleLabel.bottom > minHeiDescription)
//    {
//        self.descriptionLabel.hidden = NO;
//        self.descriptionLabel.frame = RECT(self.marginLeft, self.titleLabel.bottom, self.width, self.createdDateLabel.top - self.titleLabel.bottom);
//    }
//    else
//    {
//        self.descriptionLabel.hidden = YES;
//    }
    

    self.imageView.frame = RECT(0, 0, self.width, self.width);
    self.descriptionLabel.size = SIZE(self.width - self.marginLeft - self.marginRight, 100);
    [self.descriptionLabel sizeToFit];
    self.descriptionLabel.bottom = self.height - self.marginBottom;
    self.descriptionLabel.left = self.marginLeft;
    
    self.titleLabel.frame = RECT(self.marginLeft, self.descriptionLabel.top - 20, self.width - self.marginLeft - self.marginRight, 20);
    _gradientLayer.frame = RECT(0, self.titleLabel.top - 20, self.width, self.height - (self.titleLabel.top - 20));
}

@end
